home *** CD-ROM | disk | FTP | other *** search
- /*
- * Copyright (C) 1994, Silicon Graphics, Inc.
- * All Rights Reserved.
- *
- * This is UNPUBLISHED PROPRIETARY SOURCE CODE of Silicon Graphics, Inc.;
- * the contents of this file may not be disclosed to third parties, copied or
- * duplicated in any form, in whole or in part, without the prior written
- * permission of Silicon Graphics, Inc.
- *
- * RESTRICTED RIGHTS LEGEND:
- * Use, duplication or disclosure by the Government is subject to restrictions
- * as set forth in subdivision (c)(1)(ii) of the Rights in Technical Data
- * and Computer Software clause at DFARS 252.227-7013, and/or in similar or
- * successor clauses in the FAR, DOD or NASA FAR Supplement. Unpublished -
- * rights reserved under the Copyright Laws of the United States.
- */
- /*__________________________________________________________________________
- |
- | bliximage.c - the main part of the blix program
- |
- |
- | (c) 1993 Frans van Hoesel, Xtreme graphics software
- | hoesel@chem.rug.nl
- */
-
-
-
- #include <alloca.h>
- #include <math.h>
- #include <gl/gl.h>
- #include <gl/device.h>
- #include <gl/get.h>
- #include <gl/sphere.h>
- #include <gl/image.h>
-
- #include "bliximage.h"
- #include "blixui.h"
-
- /* from imagelib: */
- IMAGE *iopen();
- void getrow(IMAGE *, short *, int , int);
- void iclose(IMAGE *);
-
- /*________________________________________________________________________
- |
- | draw_image - draw a 2d image image
- |
- | draw a 2d image at the given coordinates; the coordianates are floats
- | in the range 0.0-1.0 and are the corners of image. The aspect ratio of
- | the image is preserved regardless of the coordinates you give.
- |
- */
-
- void draw_image(IMAGE *image, float xmin, float xmax, float ymin, float ymax) {
-
- short *rbuf, *gbuf, *bbuf, *rbuf2, *gbuf2, *bbuf2, *tmpp;
- float v1[2], v2[2];
- int x, y;
- int stp;
- float stpf;
- float max_size;
- float fac;
- float xoffset, yoffset;
-
- if (image == NULL) {
- return;
- }
- max_size = image->xsize;
- fac = max_size / (xmax - xmin);
- if (image->ysize > max_size) {
- max_size = image->ysize;
- fac = max_size / (ymax - ymin);
- }
- xoffset = ((xmax - xmin) * fac - image->xsize) / 2;
- yoffset = ((ymax - ymin) * fac - image->ysize) / 2;
- ortho2(-xmin * fac - xoffset, (1-xmin) * fac - xoffset,
- -ymin * fac - yoffset,(1-ymin) * fac - yoffset);
- rbuf = (short*) alloca(image->xsize*sizeof(short));
- gbuf = (short*) alloca(image->xsize*sizeof(short));
- bbuf = (short*) alloca(image->xsize*sizeof(short));
- rbuf2 = (short*) alloca(image->xsize*sizeof(short));
- gbuf2 = (short*) alloca(image->xsize*sizeof(short));
- bbuf2 = (short*) alloca(image->xsize*sizeof(short));
- getrow(image, rbuf2, image->ysize-1, 0);
- getrow(image, gbuf2, image->ysize-1, 1);
- getrow(image, bbuf2, image->ysize-1, 2);
- stpf = fac / (float) sizey;
- lmbind(MATERIAL,0);
- if (stpf > 1.0) {
- /* draw the image using points */
- stp = stpf;
- for (y=image->ysize - 1 - stp; y >= 0; y -= stp) {
- tmpp = rbuf2; rbuf2 = rbuf; rbuf = tmpp;
- tmpp = gbuf2; gbuf2 = gbuf; gbuf = tmpp;
- tmpp = bbuf2; bbuf2 = bbuf; bbuf = tmpp;
- getrow(image, rbuf2, y, 0);
- getrow(image, gbuf2, y, 1);
- getrow(image, bbuf2, y, 2);
- v1[0] = 0;
- v1[1] = y;
- bgnpoint();
- for (x=0; x < image->xsize; x+=stp) {
- RGBcolor(*(rbuf2+x) , *(gbuf2+x), *(bbuf2+x));
- v2f(v1);
- v1[0] += stp;
- }
- endpoint();
- }
- } else {
- /* draw the image using tmesh */
- backface(FALSE);
- for (y=image->ysize-2; y >= 0; y --) {
- tmpp = rbuf2; rbuf2 = rbuf; rbuf = tmpp;
- tmpp = gbuf2; gbuf2 = gbuf; gbuf = tmpp;
- tmpp = bbuf2; bbuf2 = bbuf; bbuf = tmpp;
- getrow(image, rbuf2, y, 0);
- getrow(image, gbuf2, y, 1);
- getrow(image, bbuf2, y, 2);
- v1[0] = 0;
- v1[1] = y;
- v2[0] = 0;
- v2[1] = y+1;
- bgntmesh();
- for (x=0; x < image->xsize; x++) {
- RGBcolor(*(rbuf2+x), *(gbuf2+x), *(bbuf2+x));
- v2f(v1);
- v1[0] += 1;
- RGBcolor(*(rbuf+x), *(gbuf+x), *(bbuf+x));
- v2f(v2);
- v2[0] += 1;
- }
- endtmesh();
- }
- backface(TRUE);
- }
- RGBcolor(0,0,0);
- linewidth(1);
- bgnclosedline();
- v1[0] = 0;
- v1[1] = 0;
- v2f(v1);
- v1[1] = image->ysize-1;
- v2f(v1);
- v1[0] = image->xsize-1;
- v2f(v1);
- v1[1] = 0;
- v2f(v1);
- endclosedline();
- }
-
-